package modular_calc;

import java.util.ArrayList;
import java.util.List;

//Do multiplication , div, add, sub on the basis of users choice. 

public class modular_calculations {

	String str1 = "";
	String str2 = "";
	char sign = ' ';

	// returns true if the character is a +,-,*,/
	boolean isSign(char s) {
		boolean flag = false;

		if (s == '+' || s == '-' || s == '*' || s == '/'|| s == '%')

		{
			flag = true;
		}

		return flag;

	}

	// splits the string into two strings separated by the operation sign
	int doSplitString(String str) {

		char[] carr = str.toCharArray();
		boolean insignblock = false;

		for (int i = 0; i < carr.length; i++) {

			boolean gotSign = isSign(carr[i]);

			if (gotSign == false && insignblock == false) {
				str1 = str1 + carr[i];

			} else if (gotSign == true) {
				sign = carr[i];
				insignblock = true;

			} else if (gotSign == false) {

				str2 = str2 + carr[i];

			}

		}

		// System.out.println("str1 " + str1 + " ");
		// System.out.println("str2 " + str2 + " ");
		// System.out.println("sign " + sign + " ");

		return doCalculation(str1, str2, sign);
	}

	// performs operation on two integers and then returns the result.
	int doCalculation(String no1, String no2, char operation) {

		int num1 = Integer.parseInt(no1);
		int num2 = Integer.parseInt(no2);
		int result = 0;
		char sign = operation;

//		System.out.println(sign);
		// switch (sign) {
		// case '+' :
		//
		// result = num1 + num2;
		// System.out.println("in +");
		//
		// case '-':
		// result = num1 - num2;
		// System.out.println("in -");
		// case '*':
		// result = num1 * num2;
		// System.out.println("in *");
		// case '/':
		// result = num1 / num2;
		// System.out.println("in /");
		// case '%':
		// result = num1 % num2;
		// System.out.println("in %");
		// default:
		// System.out.println("the operation to be performed isnt valid");
		//
		// }
		// return result;
		if (sign == '+') {
			result = num1 + num2;
		} else if (sign == '-') {
			result = num1 - num2;
		} else if (sign == '*') {
			result = num1 * num2;
		} else if (sign == '/') {
			result = num1 / num2;
		} else if (sign == '%') {
			result = num1 % num2;
		} else {
			System.out.println("the operation that is used is incorrect");
		}
		return result;
	}

}
